package com.chao.sort;

import java.util.Arrays;

/**
 * @author : Rookie
 * @description :
 * @date : 2023/7/4
 */
public class SelectSort {

    public static void main(String[] args) {
        int []arr = new int[] {3,8,2,4,1,5,9};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void sort(int []arr) {
        for (int i = 0; i < arr.length; i++) {
            int minIndex = i;
            for (int j = i; j < arr.length; j++) {
                if (arr[minIndex] > arr[j]) {
                    minIndex = j;
                }
            }
            swap(arr,i,minIndex);
        }
    }

    private static void swap(int []arr,int i,int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
